<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE FlexibleContexts #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE RankNTypes #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK hide #-}</span><span>
</span><span id="line-5"></span><span>
</span><span id="line-6"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Distribution.Compat.Environment</span><span>
</span><span id="line-7"></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Distribution.Compat.Environment.html#getEnvironment"><span class="hs-identifier">getEnvironment</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/System.Environment.html#lookupEnv"><span class="hs-identifier">lookupEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Distribution.Compat.Environment.html#setEnv"><span class="hs-identifier">setEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/System.Environment.html#unsetEnv"><span class="hs-identifier">unsetEnv</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-8"></span><span>       </span><span class="hs-keyword">where</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-11"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span>
</span><span id="line-12"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Distribution.Compat.Prelude.html"><span class="hs-identifier">Distribution.Compat.Prelude</span></a></span><span class="hs-cpp">

#ifndef mingw32_HOST_OS
</span><span class="hs-cpp">#if __GLASGOW_HASKELL__ &lt; 708
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Error</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">throwErrnoIf_</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">#endif
</span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../base/src/System.Environment.html#"><span class="hs-identifier">System.Environment</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">System</span></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/System.Environment.html#"><span class="hs-identifier">System.Environment</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/System.Environment.html#lookupEnv"><span class="hs-identifier">lookupEnv</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt;= 708
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/System.Environment.html#"><span class="hs-identifier">System.Environment</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/System.Environment.html#unsetEnv"><span class="hs-identifier">unsetEnv</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Distribution.Compat.Stack.html"><span class="hs-identifier">Distribution.Compat.Stack</span></a></span><span class="hs-cpp">

#ifdef mingw32_HOST_OS
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.html#"><span class="hs-identifier">Foreign.C</span></a></span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &lt; 708
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">nullPtr</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Windows.html#"><span class="hs-identifier">GHC.Windows</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Types</span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.String</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Error</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">throwErrnoIfMinus1_</span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Posix.Internals</span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">withFilePath</span><span> </span><span class="hs-special">)</span><span class="hs-cpp">
#endif /* mingw32_HOST_OS */
</span><span>
</span><span id="line-41"></span><span class="annot"><a href="Distribution.Compat.Environment.html#getEnvironment"><span class="hs-identifier hs-type">getEnvironment</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-cpp">
#ifdef mingw32_HOST_OS
</span><span class="hs-comment">-- On Windows, the names of environment variables are case-insensitive, but are</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- often given in mixed-case (e.g. &quot;PATH&quot; is &quot;Path&quot;), so we have to normalise</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- them.</span><span>
</span><span id="line-46"></span><span id="getEnvironment"><span class="annot"><span class="annottext">getEnvironment :: IO [(String, String)]
</span><a href="Distribution.Compat.Environment.html#getEnvironment"><span class="hs-identifier hs-var hs-var">getEnvironment</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([(String, String)] -&gt; [(String, String)])
-&gt; IO [(String, String)] -&gt; IO [(String, String)]
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">[(String, String)] -&gt; [(String, String)]
forall {b}. [(String, b)] -&gt; [(String, b)]
</span><a href="#local-6989586621679624670"><span class="hs-identifier hs-var">upcaseVars</span></a></span><span> </span><span class="annot"><span class="annottext">IO [(String, String)]
</span><a href="../../base/src/System.Environment.html#getEnvironment"><span class="hs-identifier hs-var">System.getEnvironment</span></a></span><span>
</span><span id="line-47"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-48"></span><span>    </span><span id="local-6989586621679624670"><span class="annot"><span class="annottext">upcaseVars :: [(String, b)] -&gt; [(String, b)]
</span><a href="#local-6989586621679624670"><span class="hs-identifier hs-var hs-var">upcaseVars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((String, b) -&gt; (String, b)) -&gt; [(String, b)] -&gt; [(String, b)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(String, b) -&gt; (String, b)
forall {b}. (String, b) -&gt; (String, b)
</span><a href="#local-6989586621679624668"><span class="hs-identifier hs-var">upcaseVar</span></a></span><span>
</span><span id="line-49"></span><span>    </span><span id="local-6989586621679624668"><span class="annot"><span class="annottext">upcaseVar :: (String, b) -&gt; (String, b)
</span><a href="#local-6989586621679624668"><span class="hs-identifier hs-var hs-var">upcaseVar</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679624667"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624667"><span class="hs-identifier hs-var">var</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679624666"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679624666"><span class="hs-identifier hs-var">val</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Char -&gt; Char) -&gt; String -&gt; String
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char
</span><a href="../../base/src/GHC.Unicode.html#toUpper"><span class="hs-identifier hs-var">toUpper</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624667"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679624666"><span class="hs-identifier hs-var">val</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">getEnvironment</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">System.getEnvironment</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-54"></span><span class="hs-comment">-- | @setEnv name value@ sets the specified environment variable to @value@.</span><span>
</span><span id="line-55"></span><span class="hs-comment">--</span><span>
</span><span id="line-56"></span><span class="hs-comment">-- Throws `Control.Exception.IOException` if either @name@ or @value@ is the</span><span>
</span><span id="line-57"></span><span class="hs-comment">-- empty string or contains an equals sign.</span><span>
</span><span id="line-58"></span><span class="annot"><a href="Distribution.Compat.Environment.html#setEnv"><span class="hs-identifier hs-type">setEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-59"></span><span id="setEnv"><span class="annot"><span class="annottext">setEnv :: String -&gt; String -&gt; IO ()
</span><a href="Distribution.Compat.Environment.html#setEnv"><span class="hs-identifier hs-var hs-var">setEnv</span></a></span></span><span> </span><span id="local-6989586621679624664"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624664"><span class="hs-identifier hs-var">key</span></a></span></span><span> </span><span id="local-6989586621679624663"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624663"><span class="hs-identifier hs-var">value_</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; IO ()
</span><a href="Distribution.Compat.Environment.html#setEnv_"><span class="hs-identifier hs-var">setEnv_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624664"><span class="hs-identifier hs-var">key</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624661"><span class="hs-identifier hs-var">value</span></a></span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-61"></span><span>    </span><span class="hs-comment">-- NOTE: Anything that follows NUL is ignored on both POSIX and Windows. We</span><span>
</span><span id="line-62"></span><span>    </span><span class="hs-comment">-- still strip it manually so that the null check above succeeds if a value</span><span>
</span><span id="line-63"></span><span>    </span><span class="hs-comment">-- starts with NUL.</span><span>
</span><span id="line-64"></span><span>    </span><span id="local-6989586621679624661"><span class="annot"><span class="annottext">value :: String
</span><a href="#local-6989586621679624661"><span class="hs-identifier hs-var hs-var">value</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; String
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#takeWhile"><span class="hs-identifier hs-var">takeWhile</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\NUL'</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624663"><span class="hs-identifier hs-var">value_</span></a></span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="annot"><a href="Distribution.Compat.Environment.html#setEnv_"><span class="hs-identifier hs-type">setEnv_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">

#ifdef mingw32_HOST_OS
</span><span>
</span><span id="line-70"></span><span id="setEnv_"><span class="annot"><span class="annottext">setEnv_ :: String -&gt; String -&gt; IO ()
</span><a href="Distribution.Compat.Environment.html#setEnv_"><span class="hs-identifier hs-var hs-var">setEnv_</span></a></span></span><span> </span><span id="local-6989586621679624656"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624656"><span class="hs-identifier hs-var">key</span></a></span></span><span> </span><span id="local-6989586621679624655"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624655"><span class="hs-identifier hs-var">value</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; (CWString -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (CWString -&gt; IO a) -&gt; IO a
</span><a href="../../base/src/Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624656"><span class="hs-identifier hs-var">key</span></a></span><span> </span><span class="annot"><span class="annottext">((CWString -&gt; IO ()) -&gt; IO ()) -&gt; (CWString -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679624653"><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679624653"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; (CWString -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (CWString -&gt; IO a) -&gt; IO a
</span><a href="../../base/src/Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679624655"><span class="hs-identifier hs-var">value</span></a></span><span> </span><span class="annot"><span class="annottext">((CWString -&gt; IO ()) -&gt; IO ()) -&gt; (CWString -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679624652"><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679624652"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-71"></span><span>  </span><span id="local-6989586621679624651"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679624651"><span class="hs-identifier hs-var">success</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CWString -&gt; CWString -&gt; IO Bool
</span><a href="Distribution.Compat.Environment.html#c_SetEnvironmentVariable"><span class="hs-identifier hs-var">c_SetEnvironmentVariable</span></a></span><span> </span><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679624653"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679624652"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-72"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679624651"><span class="hs-identifier hs-var">success</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; IO a
</span><a href="../../base/src/GHC.Windows.html#throwGetLastError"><span class="hs-identifier hs-var">throwGetLastError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;setEnv&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-73"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-74"></span><span>  </span><span class="annot"><span class="annottext">CallStack
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallStack
HasCallStack =&gt; CallStack
</span><a href="../../base/src/GHC.Stack.html#callStack"><span class="hs-identifier hs-var">callStack</span></a></span><span> </span><span class="hs-comment">-- TODO: attach CallStack to exception</span><span class="hs-cpp">

# if defined(i386_HOST_ARCH)
</span><span class="hs-cpp">#  define WINDOWS_CCONV stdcall
</span><span class="hs-cpp"># elif defined(x86_64_HOST_ARCH)
</span><span class="hs-cpp">#  define WINDOWS_CCONV ccall
</span><span class="hs-cpp"># else
</span><span class="hs-cpp">#  error Unknown mingw32 arch
</span><span class="hs-cpp"># endif /* i386_HOST_ARCH */
</span><span>
</span><span id="line-84"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h SetEnvironmentVariableW&quot;</span><span>
</span><span id="line-85"></span><span>  </span><span id="c_SetEnvironmentVariable"><span class="annot"><a href="Distribution.Compat.Environment.html#c_SetEnvironmentVariable"><span class="hs-identifier hs-var">c_SetEnvironmentVariable</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Windows.html#LPTSTR"><span class="hs-identifier hs-type">LPTSTR</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Windows.html#LPTSTR"><span class="hs-identifier hs-type">LPTSTR</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Prelude.IO</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-cpp">
#else
</span><span class="hs-identifier">setEnv_</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-identifier">value</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-88"></span><span>  </span><span class="hs-identifier">withFilePath</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">keyP</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-89"></span><span>    </span><span class="hs-identifier">withFilePath</span><span> </span><span class="hs-identifier">value</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">valueP</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-90"></span><span>      </span><span class="hs-identifier">throwErrnoIfMinus1_</span><span> </span><span class="hs-string">&quot;setenv&quot;</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-91"></span><span>        </span><span class="hs-identifier">c_setenv</span><span> </span><span class="hs-identifier">keyP</span><span> </span><span class="hs-identifier">valueP</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">True</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-92"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-93"></span><span>  </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">callStack</span><span> </span><span class="hs-comment">-- TODO: attach CallStack to exception</span><span>
</span><span id="line-94"></span><span>
</span><span id="line-95"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;setenv&quot;</span><span>
</span><span id="line-96"></span><span>   </span><span class="hs-identifier">c_setenv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Prelude.IO</span><span> </span><span class="hs-identifier">CInt</span><span class="hs-cpp">
#endif /* mingw32_HOST_OS */
</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &lt; 708
</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- | @unsetEnv name@ removes the specified environment variable from the</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- environment of the current process.</span><span>
</span><span id="line-103"></span><span class="hs-comment">--</span><span>
</span><span id="line-104"></span><span class="hs-comment">-- Throws `Control.Exception.IOException` if @name@ is the empty string or</span><span>
</span><span id="line-105"></span><span class="hs-comment">-- contains an equals sign.</span><span>
</span><span id="line-106"></span><span class="hs-comment">--</span><span>
</span><span id="line-107"></span><span class="hs-comment">-- @since 4.7.0.0</span><span>
</span><span id="line-108"></span><span class="hs-identifier">unsetEnv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#ifdef mingw32_HOST_OS
</span><span class="hs-identifier">unsetEnv</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withCWString</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">k</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-111"></span><span>  </span><span class="hs-identifier">success</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_SetEnvironmentVariable</span><span> </span><span class="hs-identifier">k</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-112"></span><span>  </span><span class="hs-identifier">unless</span><span> </span><span class="hs-identifier">success</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-113"></span><span>    </span><span class="hs-comment">-- We consider unsetting an environment variable that does not exist not as</span><span>
</span><span id="line-114"></span><span>    </span><span class="hs-comment">-- an error, hence we ignore eRROR_ENVVAR_NOT_FOUND.</span><span>
</span><span id="line-115"></span><span>    </span><span class="hs-identifier">err</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_GetLastError</span><span>
</span><span id="line-116"></span><span>    </span><span class="hs-identifier">unless</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">err</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">eRROR_ENVVAR_NOT_FOUND</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-117"></span><span>      </span><span class="hs-identifier">throwGetLastError</span><span> </span><span class="hs-string">&quot;unsetEnv&quot;</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-identifier">eRROR_ENVVAR_NOT_FOUND</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-120"></span><span class="hs-identifier">eRROR_ENVVAR_NOT_FOUND</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">203</span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h GetLastError&quot;</span><span>
</span><span id="line-123"></span><span>    </span><span class="hs-identifier">c_GetLastError</span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">DWORD</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">unsetEnv</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withFilePath</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">throwErrnoIf_</span><span> </span><span class="hs-special">(</span><span class="hs-operator">/=</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;unsetEnv&quot;</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">c_unsetenv</span><span class="hs-special">)</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt; 706
</span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;__hsbase_unsetenv&quot;</span><span> </span><span class="hs-identifier">c_unsetenv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Prelude.IO</span><span> </span><span class="hs-identifier">CInt</span><span class="hs-cpp">
#else
</span><span class="hs-comment">-- HACK: We hope very hard that !UNSETENV_RETURNS_VOID</span><span>
</span><span id="line-130"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;unsetenv&quot;</span><span> </span><span class="hs-identifier">c_unsetenv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Prelude.IO</span><span> </span><span class="hs-identifier">CInt</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">#endif
</span><span class="hs-cpp">
#endif
</span></pre></body></html>